/*
 * Copyright (C) 2011 hljdrl@gmail.com
 * 
 *            mail:hljdrl@gmail.com
 * 
 * All rights reserved.
 */
package org.andtools.socket;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;

import android.content.Context;

/**
 * @author hljdrl@gmail.com
 *
 */
public abstract class AbsSocket extends Thread{
	enum State{
		COM_SUCC,COM_FAIL,COM_ERROR,COM_TIMEOUT
	}
	protected SocketInfo mInfo;
	
	protected boolean running = false;
	
	protected Context mContext;
	
	protected int mAction;
	
	protected  Socket mSocket;
	
	protected byte[] mBytes[];
	
	private SocketResultListener socketResultListener;
	
	public AbsSocket(Context context,SocketInfo info,int action) {
		mInfo = info;	
		mAction = action;
		setContext(context);
	}
	void setContext(Context context){
		mContext  = context;
	}
	public Context getContext()
	{
		return mContext;
	}
	void init(){
		try {
			mSocket = new Socket(mInfo.ServiceUrl,mInfo.port);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public synchronized void sendMessage(int action,byte sends[]){
		
	}
	public synchronized void sendMessage(int action,String send){
		
	}
	@Override
	public synchronized void run() {
		running = true;
		while(running){
			
			AutoSleep();
		}
		doExit(mAction);
		System.gc();
	}
	void AutoSleep(){
		
	}
	protected void netWorking(){
		
	}
	void readReturnMessage()throws Exception{
		
	}
	
	protected void doExit(int action)
	{
		
	}
	
	public void setSocketResultListener(SocketResultListener socketResultListener) {
		this.socketResultListener = socketResultListener;
	}
	protected SocketResultListener getSocketResultListener() {
		return socketResultListener;
	}
	

}
